using System;
using System.Collections;
using System.Collections.Specialized;
using BEGDC.CC.Entity;
using BEGDC.CC.BL.Common;
using BEGDC.CC.BL.Common.Query;
using NHibernate;
using BEGDC.Utility.Castle;
using BEGDC.CC.Resource;
using System.Data;

namespace BEGDC.CC.BL.CCFlow
{
	/// <summary>
	/// AttachmentType
	/// </summary>
	public enum AttachmentType
	{
		SUMMARY,
		AGENDA,
		BUDGET,
		VISA,
		GIFT,
		CONTRACT,
		// For OCO Joan 2007/8/2
		VEHICLE,
		HOTEL,
		DEMOCENTER,
		ASBVISIT,
		//end
		OTHERS,
		ExecutiveSummary,
		CRFeedback,
		EvMeetingMinutes			
	};
	public enum UploadType
	{
		APPLICATION,
		ACTIONPOINT,
		TEMPLATE
	};

	/// <summary>
	/// Summary description for AttachmentService.
	/// </summary>
	public class AttachmentService
	{

	
		private static BEGDC.CC.BL.Common.Query.IQuery queryService= AppContainer.Instance[ServiceConst.QueryService] as BEGDC.CC.BL.Common.Query.IQuery;
		private static 	BEGDC.CC.BL.Common.IUtility utiService = AppContainer.Instance[ServiceConst.UtilityService] as IUtility;
	
		#region delete attachment or template
		public static bool DeleteFileByID(UploadType uploadType,int fileID,string errMsg)
		{
			bool operationResult;
			
			if (uploadType==UploadType.TEMPLATE)
			{
				operationResult = utiService.DeleteTemplateByID(fileID);
			}
			else
			{
				operationResult = utiService.DeleteFileById(fileID);
			}
			if (operationResult)
				return true;
			else
			{
				if (uploadType==UploadType.TEMPLATE)
					errMsg = ErrorMessage.Temp_del;
				else
					errMsg = ErrorMessage.Attach_del;
				return false;	
			}

		}
		#endregion

		#region save attachment, template
		public static bool SaveTemplates(IList templates,out string errMsg)
		{
			Template tempOld=null;
			Template tempNew=null;
			AttachmentType attType;
			bool err=false;
			errMsg="";

			for (int i=0;i<templates.Count;i++)
			{
				tempNew=(Template)templates[i];
				attType=(AttachmentType)Enum.Parse(AttachmentType.SUMMARY.GetType(),tempNew.TemplateType.DicItemKey,true);
				if (IsTemplateExist(attType,tempNew.TemplateForApp,tempNew.TemplateOrSample,out tempOld))
				{
					tempNew.Id=tempOld.Id;
					if (!utiService.UpdateTemplate(tempOld,tempNew))
						err=true;
				}
				else
				{
					if (!utiService.SaveTemplate(tempNew))
						err=true;
				}
				
				#region check saved successfully or not.
				if (err)
				{
					err=false;
					switch (attType)
					{
//						case AttachmentType.SUMMARY:
//							errMsg+=ErrorMessage.Save_summary + "\n";
//							break;
						case AttachmentType.AGENDA:
							errMsg+=ErrorMessage.Save_agenda + "\n";
							break;
						case AttachmentType.BUDGET:
							errMsg+=ErrorMessage.Save_budget + "\n";
							break;
						case AttachmentType.VISA:
							errMsg+=ErrorMessage.Save_visa + "\n";
							break;
						case AttachmentType.GIFT:
							errMsg+=ErrorMessage.Save_gift + "\n";
							break;
						case AttachmentType.CONTRACT:
							errMsg+=ErrorMessage.Save_contract + "\n";
							break;
						//<--Joan 2007/8/2
						case AttachmentType.HOTEL:
							errMsg+=ErrorMessage.Save_hotel + "\n";
							break;
						case AttachmentType.VEHICLE:
							errMsg+=ErrorMessage.Save_vehicle + "\n";
							break;
						case AttachmentType.DEMOCENTER:
							errMsg+=ErrorMessage.Save_demo + "\n";
							break;
						case AttachmentType.ASBVISIT:
							errMsg+=ErrorMessage.Save_asbvisit + "\n";
							break;
						//-->end
//						case AttachmentType.OTHERS:
//							errMsg+=ErrorMessage.Save_others + "\n";
//							break;
						default:
							break;
					}
				}
				#endregion			
			}

				
			if (errMsg=="")
				return true;
			else
			{
				errMsg = ErrorMessage.Temp_save + errMsg;
				return false;
			}			

		
		}
		public static bool SaveAttachments(IList attachments,out string errMsg)
		{
			Attachment attachNew=null;
			Attachment attachOld=null;
			AttachmentType attType;
			bool err=false;
			errMsg="";


			for (int i=0;i<attachments.Count;i++)
			{

				attachNew=(Attachment)attachments[i];
				attType=(AttachmentType)Enum.Parse(AttachmentType.SUMMARY.GetType(),attachNew.AttachmentType.DicItemKey,true);
		
				if (attType !=AttachmentType.OTHERS)
				{
					//only one attachment needed
					if (IsAttachmentExist(attachNew.Application.Id,attType,out attachOld))
					{
						attachNew.Id=attachOld.Id;
						if (!utiService.UpdateAttachment(attachOld,attachNew))
							err=true;
					}
					else
					{
						if (!utiService.SaveAttachment(attachNew))
							err=true;
					}
				}
				else
				{
					if (!utiService.SaveAttachment(attachNew))
						throw(new BEGDC.Utility.ExceptionManagement.GDCException("att_003","Error occured when uploading attachment",null));			
				}	
				#region check saved successfully or not.
				if (err)
				{
					err=false;
					switch (attType)
					{
						case AttachmentType.SUMMARY:
							errMsg+=ErrorMessage.Save_summary + "\n";
							break;
						case AttachmentType.AGENDA:
							errMsg+=ErrorMessage.Save_agenda + "\n";
							break;
						case AttachmentType.BUDGET:
							errMsg+=ErrorMessage.Save_budget + "\n";
							break;
						case AttachmentType.VISA:
							errMsg+=ErrorMessage.Save_visa + "\n";
							break;
						case AttachmentType.GIFT:
							errMsg+=ErrorMessage.Save_gift + "\n";
							break;
						case AttachmentType.CONTRACT:
							errMsg+=ErrorMessage.Save_contract + "\n";
							break;
						//<--Joan 2007/8/2
						case AttachmentType.HOTEL:
							errMsg+=ErrorMessage.Save_hotel + "\n";
							break;
						case AttachmentType.VEHICLE:
							errMsg+=ErrorMessage.Save_vehicle + "\n";
							break;
						case AttachmentType.DEMOCENTER:
							errMsg+=ErrorMessage.Save_demo + "\n";
							break;
						case AttachmentType.ASBVISIT:
							errMsg+=ErrorMessage.Save_asbvisit + "\n";
							break;
						//-->end
						case AttachmentType.OTHERS:
							errMsg+=ErrorMessage.Save_others + "\n";
							break;
						default:
							break;
					}
				}
				#endregion
			}
			if (errMsg=="")
				return true;
			else
			{
				errMsg = ErrorMessage.Attach_save + errMsg;
				return false;
			}
		}

		#endregion

		#region obsolete
//		public static bool DeleteAttachment(Attachment attachment)
//		{
//			try
//			{
//				utiService.DeleteFileById(attachment.Id);
//				System.IO.File.Delete(attachment.FilePath);
//			}
//			catch(Exception e)
//			{
//				throw(new BEGDC.Utility.ExceptionManagement.GDCException("att_001","Error occured when deleting attachment",e.InnerException));
//			}
//			return true;
//
//		}
		#endregion

		#region GetMissedAttachmentMessage()
		/// <summary>
		/// GetMissedAttachmentMessage 
		/// Check the missed attachments by given application id and required attachment type list
		/// if some attachments miss,return the alert message
		/// </summary>
		/// <param name="appID"></param>
		/// <param name="listReqiredAttachment"></param>
		/// <returns></returns>
		public static string GetMissedAttachmentMessage(int appID,IList listReqiredAttachment)
		{
			if(appID <= 0)
				return GetMissedAttachmentMessage(listReqiredAttachment);

			IList listMissed=CheckMissedAttachment(appID,listReqiredAttachment);
			if (listMissed==null || listMissed.Count==0)
				return "";
			else
				return GetMissedAttachmentMessage(listMissed);
		}

		/// <summary>
		/// GetMissedAttachmentMessage translate the missed attachment type list to alert message
		/// </summary>
		/// <param name="listMissedAttachment"></param>
		/// <returns></returns>
		public static string  GetMissedAttachmentMessage(IList listMissedAttachment)
		{
			string strMsg="";
			if (listMissedAttachment!=null && listMissedAttachment.Count>0)
			{
				for (int i=0;i<listMissedAttachment.Count;i++)
				{
					switch ((AttachmentType)listMissedAttachment[i])
					{
						case AttachmentType.SUMMARY:
							strMsg +=  SystemMessage.SUMMARYMISSED + "\\n"; 
							break;						
						case AttachmentType.AGENDA:
							strMsg +=  SystemMessage.AGENDAMISSED + "\\n"; 
							break;
						case AttachmentType.BUDGET:
							strMsg +=  SystemMessage.BUDGETMISSED + "\\n"; 
							break;
						case AttachmentType.VISA:
							strMsg +=  SystemMessage.VISAMISSED + "\\n"; 
							break;
						case AttachmentType.GIFT:
							strMsg +=  SystemMessage.GIFTMISSED + "\\n"; 
							break;
						case AttachmentType.CONTRACT:
							strMsg +=  SystemMessage.CONTRACTMISSED + "\\n"; 
							break;
							//<--Joan 2007/8/2
						case AttachmentType.HOTEL:
							strMsg +=  SystemMessage.HOTELMISSED + "\\n"; 
							break;
						case AttachmentType.VEHICLE:
							strMsg +=  SystemMessage.VEHICLEMISSED + "\\n"; 
							break;
						case AttachmentType.DEMOCENTER:
							strMsg +=  SystemMessage.DEMOMISSED + "\\n"; 
							break;
						case AttachmentType.ASBVISIT:
							strMsg +=  SystemMessage.ASBVISITMISSED + "\\n"; 
							break;
							//-->end 
						default:
							break;
					}
				}
			}
			if (strMsg=="")
				return strMsg;
			else
			{
				strMsg = "Please provide following attachment(s):\\n" + strMsg;
				return strMsg;
			}
		}

		/// GetMissedAttachmentMessage 
		/// Check the missed attachments by given application id, the business logic is implemented in this method.
		/// if some attachments miss,return the alert message
		public static string  GetMissedAttachmentMessage(int appID)
		{
			if(appID <= 0)
				return "Please save the application first.";

			IList list=GetMissedAttachments(appID);
			return GetMissedAttachmentMessage(list);
		}
		#endregion

		#region get attachment missed for the application, return AttachmentType list
		public static IList GetMissedAttachments(int appID)
		{		
			IList listRequired=GetAttachmentRequired(appID,false);
			if (listRequired==null)
				return listRequired;

			return CheckMissedAttachment(appID,listRequired);
		}
	
		#endregion

		#region get attachment to be uploaded for attachment control,return AttachmentType list
		public static IList GetAttachmentToBeUpload(int appID)
		{
			return GetAttachmentRequired(appID,true);
		}
		#endregion		


		#region private methods

		#region check if attachment or template exists or not
		private static bool IsAttachmentExist(int appID, AttachmentType attachmentType,out Attachment attachment)
		{	
			Attachment attach=null;
			try
			{
				DataTable dt=queryService.GetAttachmentByAppId(appID);
				if (dt!=null && dt.Rows.Count>0)
				{
					for (int i=0;i<dt.Rows.Count;i++)
					{
						if (dt.Rows[i]["AttachmentType"].ToString()==attachmentType.ToString())
						{
							attach=new Attachment();
							attach.Id=Convert.ToInt32(dt.Rows[i]["FileID"]);
							attach.Application =new Application();
							attach.Application.Id=appID;
							attach.FileName=dt.Rows[i]["FileName"].ToString();
							attach.FilePath=dt.Rows[i]["FilePath"].ToString();
							attach.Owner=dt.Rows[i]["Owner"].ToString();
							attach.Date=Convert.ToDateTime(dt.Rows[i]["Date"]);

							attach.AttachmentType=new DicItem();
							attach.AttachmentType.DicItemKey=dt.Rows[i]["AttachmentType"].ToString();
							attach.AttachmentType.Id=Convert.ToInt32(dt.Rows[i]["AttachmentTypeID"]);
							attach.AttachmentType.DicType=new BEGDC.CC.Entity.DicType(BEGDC.CC.BL.Common.DicType.ATTACHMENTTYPE,"",false,"ALL");
							break;
						}
					}
				}
			}
			catch (Exception e)
			{
				CCS.Utility.LogAccess.WriteErrLog( "IsAttachmentExist", e.Message );
				throw(new BEGDC.Utility.ExceptionManagement.GDCException("att_002","Error occured when querying attachment",e.InnerException));			
			}
			if (attach!=null)
			{
				attachment=attach;
				return true;
			}
			else
			{
				attachment=null;
				return false;
			}
			
		}

		private static bool IsTemplateExist(AttachmentType attachmentType,string tempForApp, string tempSample, out Template template)
		{
			Template temp=null;
			DataTable dt = null;
			try
			{
				 dt=queryService.GetTemplates();
				if (dt!=null)
				{
					for (int i=0;i<dt.Rows.Count;i++)
					{
						if (dt.Rows[i]["TemplateType"].ToString()==attachmentType.ToString() && dt.Rows[i]["TemplateForApp"].ToString()==tempForApp && dt.Rows[i]["TemplateOrSample"].ToString()==tempSample)
						{
							temp=new Template();
							temp.Id=Convert.ToInt32(dt.Rows[i]["TemplateID"]);
							temp.FileName=dt.Rows[i]["FileName"].ToString();
							temp.FilePath=dt.Rows[i]["FilePath"].ToString();
							temp.Owner=dt.Rows[i]["Owner"].ToString();
							temp.LastUpdate=Convert.ToDateTime(dt.Rows[i]["LastUpdate"]);
							temp.TemplateForApp=dt.Rows[i]["TemplateForApp"].ToString();
							temp.TemplateOrSample=dt.Rows[i]["TemplateOrSample"].ToString();

							temp.TemplateType=new DicItem();
							temp.TemplateType.DicItemKey=dt.Rows[i]["TemplateType"].ToString();
							temp.TemplateType.Id=Convert.ToInt32(dt.Rows[i]["TemplateTypeID"]);

							temp.TemplateType.DicType=new BEGDC.CC.Entity.DicType(BEGDC.CC.BL.Common.DicType.ATTACHMENTTYPE,"",false,"ALL");
							
							break;

						}

					}
				}
			}
			catch
			{
				
			}			
			if (temp!=null)
			{
				template=temp;
				return true;
			}
			else
			{
				template=null;
				return false;
			}
		}

		#endregion

		#region static GetAttachmentRequired, return AttachmentType list
		private static IList GetAttachmentRequired(int appID,bool isForUpload)
		{

			//get application
			Entity.Application app=AttachmentService.queryService.GetApplication(appID);
			if (app==null)
			{
				throw(new BEGDC.Utility.ExceptionManagement.GDCException("app0001","Couldn't find the application.", null));
			}

			BEGDC.CC.Entity.LogisticalInfo lgsInfo=AttachmentService.queryService.GetLogisticalInfo(appID);
			BEGDC.CC.Entity.BusinessPurpose busiPurpose =AttachmentService.queryService.GetBusinessPurposeInfo(appID);

			IList listRequired=new System.Collections.ArrayList();

			#region check required attachment type for the application 
			
			switch(app.ApplicationType)
			{
				case "EV":
					listRequired.Add(AttachmentType.SUMMARY);
					listRequired.Add(AttachmentType.AGENDA);
					break;
				case "CV":
					listRequired.Add(AttachmentType.AGENDA);
					listRequired.Add(AttachmentType.BUDGET);
					if (lgsInfo!=null)
					{
						if (lgsInfo.IsNeedGift)
							listRequired.Add(AttachmentType.GIFT);
					}
					if (busiPurpose!=null)
					{
						if (busiPurpose.IsNeedInvitationLetter)
							listRequired.Add(AttachmentType.VISA);
						if (busiPurpose.IsInSalesContract)
							listRequired.Add(AttachmentType.CONTRACT);
					}
					break;
				case "CO":
				case "CR":
					if (app.IsTransition)
					{
						listRequired.Add(AttachmentType.AGENDA);
						listRequired.Add(AttachmentType.BUDGET);
					}
					if (lgsInfo!=null)
					{
						if (lgsInfo.IsNeedGift)
							listRequired.Add(AttachmentType.GIFT);
					}
					Common.Query.IQuery queryService = BEGDC.Utility.Castle.AppContainer.Instance[BEGDC.CC.BL.Common.ServiceConst.QueryService] as Common.Query.IQuery;
					FlowInstance flowInstance = queryService.QueryFlowInstance( appID );
					if( flowInstance != null )
					{
						if( flowInstance.CurrentActiveStep.StepCode == BEGDC.CC.BL.Workflow.WorkTransition.End )
						{
							listRequired.Add( AttachmentType.CRFeedback );
						}
					}
					break;
				//<--changed joan 2007/8/2
				case "OCR":
					listRequired.Add(AttachmentType.AGENDA);
					listRequired.Add(AttachmentType.BUDGET);
					//Hotel,Gift,Vehicle
					if (lgsInfo!=null)
					{
						if (lgsInfo.IsNeedGift)
							listRequired.Add(AttachmentType.GIFT);
						if (lgsInfo.IsNeedHotel)
							listRequired.Add(AttachmentType.HOTEL);
						if (lgsInfo.IsNeedGroundTransportation)
							listRequired.Add(AttachmentType.VEHICLE);
					}
					//get visiting site info
					DataTable dtSite = AttachmentService.queryService.GetVisitingSite(appID);
					if (dtSite.Rows.Count >0)
					{
						IList list =AttachmentService.utiService.BuildDicList( BEGDC.CC.BL.Common.DicType.OCOVisitingSites);
						for (int i=0;i<dtSite.Rows.Count;i++)
						{
							for (int j=0;j<list.Count;j++)
							{
								if (dtSite.Rows[i]["DicItemID"].ToString()==((DicItem)list[j]).Id.ToString())
								{
                                    if (((DicItem)list[j]).Description.ToUpper() == "OCO-Shanghai Factory".ToUpper()) ;
                                    //listRequired.Add(AttachmentType.ASBVISIT);
                                    else if (((DicItem)list[j]).Description.ToUpper() == "OCO-Shanghai Demo Center".ToUpper()) ;
                                        //listRequired.Add(AttachmentType.DEMOCENTER);
                                        break;
								}
							}
						}

					}

					if (!app.IsTransition)
					{
						//OCR-B
						if (busiPurpose!=null)
						{
							if (busiPurpose.IsNeedInvitationLetter)
								listRequired.Add(AttachmentType.VISA);
						}					
					}
					break;
				case "OCV":
					listRequired.Add(AttachmentType.AGENDA);
					listRequired.Add(AttachmentType.BUDGET);
					listRequired.Add(AttachmentType.SUMMARY);
					
					if (lgsInfo!=null)
					{
						if (lgsInfo.IsNeedGift)
							listRequired.Add(AttachmentType.GIFT);
					}
					if (busiPurpose!=null)
					{
						if (busiPurpose.IsNeedInvitationLetter)
							listRequired.Add(AttachmentType.VISA);
					}

					break;
				case "EBD":
					listRequired.Add(AttachmentType.AGENDA);
					listRequired.Add(AttachmentType.BUDGET);
					//Hotel,Gift,Vehicle
					if (lgsInfo!=null)
					{
						if (lgsInfo.IsNeedGift)
							listRequired.Add(AttachmentType.GIFT);
						if (lgsInfo.IsNeedHotel)
							listRequired.Add(AttachmentType.HOTEL);
						if (lgsInfo.IsNeedGroundTransportation)
							listRequired.Add(AttachmentType.VEHICLE);
					}
					//get visiting site info
					dtSite = AttachmentService.queryService.GetVisitingSite(appID);
					if (dtSite.Rows.Count >0)
					{
						IList list =AttachmentService.utiService.BuildDicList( BEGDC.CC.BL.Common.DicType.OCOVisitingSites);
						for (int i=0;i<dtSite.Rows.Count;i++)
						{
							for (int j=0;j<list.Count;j++)
							{
								if (dtSite.Rows[i]["DicItemID"].ToString()==((DicItem)list[j]).Id.ToString())
								{
									if (((DicItem)list[j]).Description.ToUpper()=="OCO-Shanghai Factory".ToUpper())
										listRequired.Add(AttachmentType.ASBVISIT);
									else if (((DicItem)list[j]).Description.ToUpper()=="OCO-Shanghai Demo Center".ToUpper())
										listRequired.Add(AttachmentType.DEMOCENTER);
									break;
								}
							}
						}

					}

					if (!app.IsTransition)
					{
						//EBD-B
						if (busiPurpose!=null)
						{
							if (busiPurpose.IsNeedInvitationLetter)
								listRequired.Add(AttachmentType.VISA);
						}					
					}
					break;
				case "EBDCV":
					listRequired.Add(AttachmentType.AGENDA);
					listRequired.Add(AttachmentType.BUDGET);
					listRequired.Add(AttachmentType.SUMMARY);
					
					if (lgsInfo!=null)
					{
						if (lgsInfo.IsNeedGift)
							listRequired.Add(AttachmentType.GIFT);
					}
					if (busiPurpose!=null)
					{
						if (busiPurpose.IsNeedInvitationLetter)
							listRequired.Add(AttachmentType.VISA);
					}

					break;
				case "ESC":
					listRequired.Add(AttachmentType.AGENDA);
					listRequired.Add(AttachmentType.BUDGET);
					//Hotel,Gift,Vehicle
					if (lgsInfo!=null)
					{
						if (lgsInfo.IsNeedGift)
							listRequired.Add(AttachmentType.GIFT);
						if (lgsInfo.IsNeedHotel)
							listRequired.Add(AttachmentType.HOTEL);
						if (lgsInfo.IsNeedGroundTransportation)
							listRequired.Add(AttachmentType.VEHICLE);
					}
					//get visiting site info
					dtSite = AttachmentService.queryService.GetVisitingSite(appID);
					if (dtSite.Rows.Count >0)
					{
						IList list =AttachmentService.utiService.BuildDicList( BEGDC.CC.BL.Common.DicType.OCOVisitingSites);
						for (int i=0;i<dtSite.Rows.Count;i++)
						{
							for (int j=0;j<list.Count;j++)
							{
								if (dtSite.Rows[i]["DicItemID"].ToString()==((DicItem)list[j]).Id.ToString())
								{
									if (((DicItem)list[j]).Description.ToUpper()=="OCO-Shanghai Factory".ToUpper())
										listRequired.Add(AttachmentType.ASBVISIT);
									else if (((DicItem)list[j]).Description.ToUpper()=="OCO-Shanghai Demo Center".ToUpper())
										listRequired.Add(AttachmentType.DEMOCENTER);
									break;
								}
							}
						}

					}

					if (!app.IsTransition)
					{
						//ESC-B
						if (busiPurpose!=null)
						{
							if (busiPurpose.IsNeedInvitationLetter)
								listRequired.Add(AttachmentType.VISA);
						}					
					}
					break;
				case "ESCCV":
					listRequired.Add(AttachmentType.AGENDA);
					listRequired.Add(AttachmentType.BUDGET);
					listRequired.Add(AttachmentType.SUMMARY);
					
					if (lgsInfo!=null)
					{
						if (lgsInfo.IsNeedGift)
							listRequired.Add(AttachmentType.GIFT);
					}
					if (busiPurpose!=null)
					{
						if (busiPurpose.IsNeedInvitationLetter)
							listRequired.Add(AttachmentType.VISA);
					}

					break;
				//-->end
				default:
					//throw (new BEGDC.Utility.ExceptionManagement.GDCException("app0002","Application type is not defined.",null));
					break;
			}	
			#endregion 
			
			
			#region for upload, OTHERS can be uploaded 

			if (isForUpload)
				listRequired.Add(AttachmentType.OTHERS);
			#endregion 

			return listRequired;

		}
		#endregion


		#region CheckMissedAttachment
		private static IList CheckMissedAttachment(int appID, IList list)
		{
			IList listMissed=new ArrayList();
			DataTable dt=AttachmentService.queryService.GetAttachmentByAppId(appID);

			if (dt==null || dt.Rows.Count==0)
			{
				return list;
			}
			else
			{
				for (int i=0;i<list.Count;i++)
				{
					for (int j=0;j<dt.Rows.Count;j++)
					{
						if (dt.Rows[j]["AttachmentType"].ToString()==list[i].ToString())
						{
							list.Remove(list[i]);
							i--;
							break;
						}
					}
				}
			}

			listMissed = list;
			return listMissed;

		}
		#endregion

		#endregion
		
	}
}
